package com.qf.web;

import com.qf.dao.UserDao;
import com.qf.service.OrderService;
import com.qf.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;

@Controller
public class UserController {

//    private UserService userService = new UserServiceImpl();

    public static void main(String[] args) {
//        ApplicationContext ioc = new ClassPathXmlApplicationContext("spring.xml");
        ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext("spring.xml");

//        UserDao userDao = (UserDao) ioc.getBean("userDao");

        UserDao userDao = ioc.getBean(UserDao.class);

//        OrderService orderService = (OrderService) ioc.getBean("orderServiceImpl");

        OrderService orderService = ioc.getBean(OrderService.class);

//        UserService userService = (UserService) ioc.getBean("userService");

        //通过类型获取时，只允许在ioc容器中有且只有唯一一个该类型的bean对象，否则就报错了
        UserService userService = ioc.getBean(UserService.class);

        System.out.println(userDao);
        System.out.println(orderService);
        System.out.println(userService);


        ioc.close();
    }
}
